define(function(require, exports, module) {

	require("layout");
	require("modal");
	var fit = require("fitdatagrid");

	module.exports = function() {

		return {

			data: {
				search: {
					placeholder: $.i18n.prop("info.search.placeholder"),
					button:$.i18n.prop("info.search")
				},
				button:{
					disabled:false
				},
				paging:{
					height:200,
					data:[],
					columns:[],
					selections:[],
					loading:true,
					page:1,
					pageSize:10,
					total:0
				}
			},
			methods: {

				init:function(params) {
					//表格自适应高度
					fit.fit($(this.$el).find(".layout-main"), this.paging);
					this.paging.columns = [
						{
	                        type: 'selection',
	                        width: 50,
	                        align: 'center'
	                    },
						{
	                        title: 'Name',
	                        key: 'name'
	                    },
	                    {
	                        title: 'Age',
	                        key: 'age'
	                    },
	                    {
	                        title: 'Address',
	                        key: 'address'
	                    }
					];
					this.load();
					return false;
				},
				load:function() {
					var me = this;
					me.paging.loading = true;
					//模拟异步读取数据
					setTimeout(function() {
						me.paging.total = 100;
						me.paging.data = [{
	                        name: 'John Brown',
	                        age: 18,
	                        address: 'New York No. 1 Lake Park',
	                        date: '2016-10-03'
	                    },
	                    {
	                        name: 'Jim Green',
	                        age: 24,
	                        address: 'London No. 1 Lake Park',
	                        date: '2016-10-01'
	                    },
	                    {
	                        name: 'Joe Black',
	                        age: 30,
	                        address: 'Sydney No. 1 Lake Park',
	                        date: '2016-10-02'
	                    },
	                    {
	                        name: 'Jon Snow',
	                        age: 26,
	                        address: 'Ottawa No. 2 Lake Park',
	                        date: '2016-10-04'
	                    },
	                    {
	                        name: 'John Brown',
	                        age: 18,
	                        address: 'New York No. 1 Lake Park',
	                        date: '2016-10-03'
	                    },
	                    {
	                        name: 'Jim Green',
	                        age: 24,
	                        address: 'London No. 1 Lake Park',
	                        date: '2016-10-01'
	                    },
	                    {
	                        name: 'Joe Black',
	                        age: 30,
	                        address: 'Sydney No. 1 Lake Park',
	                        date: '2016-10-02'
	                    },
	                    {
	                        name: 'Jon Snow',
	                        age: 26,
	                        address: 'Ottawa No. 2 Lake Park',
	                        date: '2016-10-04'
	                    }];
	                    me.paging.loading = false;
	                    me.$nextTick(function() {
	                    	me.loading("close");
	                    });
					}, 2000);
				},
				onSearch:function(value) {
					console.log(this.$refs.selection);
					console.log(value);
					this.paging.page = 1;
					this.load();
				},
				onSelectionChange:function(rows) {
					this.paging.selections = rows;
				},
				onPageChange:function(page) {
					console.log(page);
					this.paging.page = page;
					this.load();
				},
				destroy: function() {
					
				},
				onAddClicked:function() {
					$.msginfo("添加");
					$.info("内容", function() {
						var me = this;
                    	console.log("确定,2秒后关闭");
                    	setTimeout(function(){
                    		me.remove();
                    	}, 2000);
					}, true);
				},
				onEditClicked:function() {
					console.log("编辑");
					$.alert("编辑内容", function() {console.log("确定")});
				},
				onRemoveClicked:function() {
					console.log("删除");
					$.confirm("确定要删除吗？", function(isOk) {
						console.log(isOk);
						if(isOk) {
							var me = this;
							setTimeout(function(){
								me.remove();
							}, 2000);
						}
					}, true);
					
				},
				onAllocClicked:function() {
					console.log("分配");
					$.prompt({
						msg:"请输入姓名", 
						callback:function(value) {
							console.log(value);
						}
					});
				}
			}
		}
	}

});